#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

void solve(){
    int n, m;
    string s1, s2;
    int t1 = 0;
    cin >> n >> m >> s1 >> s2;

    if(s1.substr(n - m + 1, n) == s2.substr(1, m)){

        for(int i = 0; i < n - m + 1; i ++){
            if(s1[i] == s2[0]){
                printf("YES\n");
                return;
            }
        }
    }
    printf("NO\n");


}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    int T;
    cin >> T;
    while(T--){
        solve();
    }

    return 0;
}